package com.podcstr.entity;

import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Comparator;

/**
 * @author azim
 * @since 5/12/13 
 */

@Entity
@Table(name = "tb_categories")
@NamedQueries(value = {
        @NamedQuery(name = "tb_categories.findByCategoryName", query = "SELECT c FROM Category c WHERE c.name =:name"),
        @NamedQuery(name = "tb_categories.findParentCategories", query = "SELECT c FROM Category c WHERE c.parent =0"),
        @NamedQuery(name = "tb_categories.findChildCategories", query = "SELECT c FROM Category c WHERE c.parent =:parent")
})
public class Category extends PersistanceObject {

    @NotNull
    private String name;

    @Size(max = 100)
    private String description;

    private long parent = 0;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public long getParent() {
        return parent;
    }

    public void setParent(long parent) {
        this.parent = parent;
    }

    public static Comparator<Category> CompareByName = new Comparator<Category>() {
        @Override
        public int compare(Category o1, Category o2) {

            return o1.getName().compareTo(o2.getName());
        }
    };
}
